#include "item.h"
#include "draw.h"
#include "state.h"

Item::Item(const std::string &t)
    : text(t), width(0), left(nullptr), right(nullptr), out(false)
{
    // Calculate width on creation (uses global draw context)
    State &state = getState();
    if (state.drw)
    {
        width = state.drw->getTextWidth(text.c_str());
    }
}

void appendItem(Item *item, Item **listHead, Item **listTail)
{
    if (!item)
        return;
    if (!*listHead)
    {
        *listHead = item;
        *listTail = item;
    }
    else
    {
        (*listTail)->right = item;
        item->left = *listTail;
        *listTail = item;
    }
}
